Today, I'm going to reset my trap.
In the last video, we made it so that when you step on the pressure plate, the boulder will roll down
the hill and off into the world.
But we need to reset our trap.
So let's go ahead and get started with that.
Let's go to workspace.
We'll go to the Boulder trap.
Here's my boulder.
And I think what I'm going to do is I'm going to make this one invisible and then I'm just going to
clone new ones when I go to reset the trap.
Right?
So I got the boulder the way I want it.
I'm going to go here with that selected, go to transparency.
Make that one.
Right now we can't see the boulder and then let's go down to can collide.
Uncheck that.
Now we can't touch the boulder and then we'll go to anchored and we'll anchor it.
And now it's not going to move.
That is my template.
We can't see it, but we're going to make new boulders from that one and then make them visible when
we need them.
So let's go to our trigger it now, Right?
Boom.
Oh, it's a new Roblox update.
I'm just going to do a second time.
There we go.
Let's get a variable for our Boulder template.
Boulder template.
And that's in the Boulder Trap dot Boulder.
The thing we just changed and then we're going to get another variable.
I'm going to call those curve Boulder.
That's going to be my current boulder that I cloned from my Boulder template.
There we go.
And I need a balance flag to prevent things from firing.
Too often we only want to fire it after we reset the trap.
So I'm going to say local can trigger and we could set that to false.
Don't worry, we're going to turn it on when we start the game.
I'm going to need something called the debris service.
Right.
So we'll make a variable debris, gain colon, get service debris, the debris service you can use to
clean objects up after a period of time.
It destroys them after a given period of time.
So I'm going to destroy the boulder after I create it, after it rolls off into oblivion.
All right.
Now we'll do this function local function called set trap.
What are we going to do is set trap.
We're going to make a boulder first.
So I'll say kerb older.
And that's going to be from the Boulder template, Colon Cloud.
So this does a deep clone.
It's going to make exact copy of a bolder template, including being invisible, but also any scripts
or sounds underneath it, too.
That's kind of convenient, but it is invisible.
So let's get our cover bolder and then make it visible so transparency will now equal zero.
Curve older, remember can collide.
We need to turn that onto malicious people so we have can collide is true kerb older anchored.
We need to make that.
Ball.
So it rolls down the ramp and then we need curb, boulders, parent to be somewhere in the workspace
or else we won't see it.
It won't appear in the workspace.
So I think I'll make the parent the bolder trap because that is in the workspace, the stoppers, right?
So when we touched our when we touched our trigger plate, we made the stopper can collide false and
we made it invisible.
Well, we've got to reset those so we'll say stopper can collide.
Set that to true or we'll keep it true.
If we're starting up the game, we'll get the stopper transparency, we'll make that equal to zero.
Now, this is going to be kind of tricky.
What I'm going to do is I'm going to get the curb older dot destroying.
I'm going to capture the destroying method when I create my boulder and I'm going to connect it, I
should say I'm going to catch the destroying event.
I'm going to connect it to an anonymous function is going to be crazy.
That's going to call set trap.
So when I destroy a boulder, I'm resetting my trap by calling set trap.
So this isn't going to fire right away.
I am just connecting the destroying event on the current boulder to do this.
Actually, we could do even less than that.
We could do this.
But I was thinking of putting more in there than that.
There we go.
Connect it to set trap calls it again.
Pretty crazy, huh?
All right, now let's do this.
Let's get the can trigger and we'll set it to true.
Everything is ready to go.
Well, when we go down to on touch, what's going to happen there?
Let's see.
We free up our boulder by making the stoppers can collide.
False.
And the transparency to one.
I got rid of that space.
I didn't like it.
What I'm going to do is I'm also going to get the can trigger set that to false right.
And that way when we touch our pressure plate, if can trigger is true, will be OC, then we'll go
in here.
But once I trigger it, I don't want to be able to fire this if statement off again until I reset it
somewhere else.
Where?
Right in here.
Once we make the fall or the boulder, we're going to say, Oh, it's true.
Now we can trigger it again.
That's kind of that's kind of cool.
I like that.
All right.
What else are we going to do down here?
We're going to say debris.
We're going to get our debris variable, add item, boulder, and then the second value.
So we're going to add the debris.
So we're going to add the current boulder to the debris service and give it a time to live.
The lifetime is in seconds.
So I'm going to say 8 seconds.
That works out for me.
You don't want it to live too long because it rolls off the edge and then it goes out of scope of the
game and is destroyed by the game.
The destroying event is not going to fire.
You have to actually destroy it with the debris service or the colon destroy method on the current boulder.
So this will work.
Don't make this too long.
If it's too short, it'll look funny because it'll disappear before it's out of view.
I think we're good.
Oh, you know what, though?
We still have to call this an initial time because we have it set up so that every time it destroys,
we're going to call it again.
But we've got to call it at least once.
I'm going to call it down all the way down at the bottom.
Let's do it.
All right, Where's my boulder trap?
Here it is.
We're going to hit our pressure plate.
Get out of the way.
It won't hurt us anyway.
We need to anchor that.
As soon as that.
That kind of bounced around, it disappeared.
Boom!
There it is.
Made a new one.
So I don't know if we'll be able to catch that.
Maybe if we back up really far.
There we go.
Let's see what happens.
Yeah.
So you could actually even make that like one or 2 seconds longer because it destroyed right as it hit
the edge.
But I like it.
I think it works pretty good.
Let's go ahead and get this pressure plate and anchor it and then we'll be done for this video.
We'll add sound and damage in the next one.
We hit the alt key and select that, and that's going to select that in here.
That's a little a little cheat.
It's kind of cool.
Let's go ahead and make that anchored so I don't flop around.
Cool beans.
I will see you in the next video.
Sound and damage.